package com.lv.fast.DO;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.lv.fast.DTO.SysMenuDTO;
import com.lv.fast.constant.JsonConstant;
import com.lv.fast.model.ExtendBean;
import lombok.Data;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;

import java.util.HashSet;

/**
 * @Description
 * @Author jie.lv
 */
@Data
@TableName("sys_menu")
public class SysMenuDO extends ExtendBean {

    @TableField("menu_name")
    private String name;

    private String menuDescribe;

    private String url;

    private String type;

    private String icon;

    private Integer orderNum;

    private String perms;

    private String parentId;

    @SneakyThrows
    public SysMenuDTO toDTO(){
        SysMenuDTO sysMenuDTO = BeanUtil.copyProperties(this, SysMenuDTO.class, "perms");
        String perms = this.perms;
        if (StringUtils.isNoneBlank(perms)){
            HashSet<String> permSet = JsonConstant.objectMapper.readValue(perms, HashSet.class);
            sysMenuDTO.setPerms(permSet);
        }
        return sysMenuDTO;
    }
}
